<include file="Public/min-header"/>
<style>
    ul.group-list {
        width: 96%;min-width: 1000px; margin: auto 5px;list-style: disc outside none;
    }
    ul.group-list li {
        white-space: nowrap;float: left;
        width: 150px; height: 25px;
        padding: 3px 5px;list-style-type: none;
        list-style-position: outside;border: 0px;margin: 0px;
    }
</style>
<script type="text/javascript">
    window.UEDITOR_Admin_URL = "__ROOT__/Public/plugins/Ueditor/";
    var URL_upload = "{$URL_upload}";
    var URL_fileUp = "{$URL_fileUp}";
    var URL_scrawlUp = "{$URL_scrawlUp}";
    var URL_getRemoteImage = "{$URL_getRemoteImage}";
    var URL_imageManager = "{$URL_imageManager}";
    var URL_imageUp = "{$URL_imageUp}";
    var URL_getMovie = "{$URL_getMovie}";
    var URL_home = "{$URL_home}";</script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/plugins/Ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/plugins/Ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/plugins/Ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
    var editor;
    $(function () {
        //具体参数配置在  editor_config.js  中
        var options = {
            zIndex: 999,
            initialFrameWidth: "95%", //初化宽度
            initialFrameHeight: 400, //初化高度
            focus: false, //初始化时，是否让编辑器获得焦点true或false
            maximumWords: 99999,
            removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign', //允许的最大字符数 'fullscreen',
            pasteplain: false, //是否默认为纯文本粘贴。false为不使用纯文本粘贴，true为使用纯文本粘贴
            autoHeightEnabled: true,
            /*   autotypeset: {
             mergeEmptyline: true, //合并空行
             removeClass: true, //去掉冗余的class
             removeEmptyline: false, //去掉空行
             textAlign: "left", //段落的排版方式，可以是 left,right,center,justify 去掉这个属性表示不执行排版
             imageBlockLine: 'center', //图片的浮动方式，独占一行剧中,左右浮动，默认: center,left,right,none 去掉这个属性表示不执行排版
             pasteFilter: false, //根据规则过滤没事粘贴进来的内容
             clearFontSize: false, //去掉所有的内嵌字号，使用编辑器默认的字号
             clearFontFamily: false, //去掉所有的内嵌字体，使用编辑器默认的字体
             removeEmptyNode: false, // 去掉空节点
             //可以去掉的标签
             removeTagNames: {
             "font": 1
             },
             indent: false, // 行首缩进
             indentValue: '0em' //行首缩进的大小
             },*/
            toolbars: [
                ['fullscreen', 'source', '|', 'undo', 'redo',
                    '|', 'bold', 'italic', 'underline', 'fontborder',
                    'strikethrough', 'superscript', 'subscript',
                    'removeformat', 'formatmatch', 'autotypeset',
                    'blockquote', 'pasteplain', '|', 'forecolor',
                    'backcolor', 'insertorderedlist',
                    'insertunorderedlist', 'selectall', 'cleardoc', '|',
                    'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
                    'customstyle', 'paragraph', 'fontfamily', 'fontsize',
                    '|', 'directionalityltr', 'directionalityrtl',
                    'indent', '|', 'justifyleft', 'justifycenter',
                    'justifyright', 'justifyjustify', '|', 'touppercase',
                    'tolowercase', '|', 'link', 'unlink', 'anchor', '|',
                    'imagenone', 'imageleft', 'imageright', 'imagecenter',
                    '|', 'insertimage', 'emotion', 'insertvideo',
                    'attachment', 'map', 'gmap', 'insertframe',
                    'insertcode', 'webapp', 'pagebreak', 'template',
                    'background', '|', 'horizontal', 'date', 'time',
                    'spechars', 'wordimage', '|',
                    'inserttable', 'deletetable',
                    'insertparagraphbeforetable', 'insertrow', 'deleterow',
                    'insertcol', 'deletecol', 'mergecells', 'mergeright',
                    'mergedown', 'splittocells', 'splittorows',
                    'splittocols', '|', 'print', 'preview', 'searchreplace'
                ]
            ]
        };
        editor = new UE.ui.Editor(options);
        editor.render("goods_content"); //  指定 textarea 的  id 为 goods_content
    });</script>
<div class="wrapper">
    <include file="Public/breadcrumb" />
    <section class="content">
        <div class="container-fluid">
            <div class="pull-right">
                <a href="javascript:history.go(-1)" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="返回"><i class="fa fa-reply"></i></a>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="fa fa-list"></i>商品详情</h3>
                </div>
                <div class="panel-body">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_tongyong" data-toggle="tab">通用信息</a></li>
                        <li><a href="#tab_goods_spec" data-toggle="tab">商品规格</a></li>
                        <li><a href="#tab_goods_img" data-toggle="tab">商品相册</a></li>
                    </ul>
                    <form method="post" id="addEditGoodsForm" action="{:U('Admin/Goods/addEditGoodsForm')}" enctype="multipart/form-data">
                        <div class="tab-content">
                            <div class="tab-pane active" id="tab_tongyong">
                                <table class="table table-bordered">
                                    <tbody>
                                        <tr>
                                            <td class = "text-right">商品名称:</td>
                                            <td>
                                                <input type="text" value="{$goodsInfo.goods_name}" name="goods_name" class="form-control" style="width:550px;" />
                                                <span id="err_goods_name" style="color:#F00; display:none;"></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class = "text-right">商品简介:</td>
                                            <td>
                                                <textarea rows="3" cols="80" name="goods_remark" class = "form-control">{$goodsInfo.goods_remark}</textarea>
                                                <span id="err_goods_remark" style="color:#F00; display:none;"></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class = "text-right">商品分类:</td>
                                            <td>
                                                <div class="col-xs-3" style = "width:250px">
                                                    <select name="cat_id" id="cat_id" onchange="getCategory(this.value, 'cat_id_2', '0');" class="form-control" style="width:250px;margin-left:-15px;">
                                                        <option value="0">请选择商品分类</option>
                                                        <foreach name="cat_list" item="v" key="k">
                                                            <option value="{$v['id']}" <if condition="$v['id'] eq $goodsInfo['cat_id']">selected="selected"</if> > {$v['name']}
                                                            </option>
                                                        </foreach>
                                                    </select>
                                                </div>
                                                <div class="col-xs-3" style = "width:250px;margin-left:30px;">
                                                    <select name="second_cat_id" id="cat_id_2" class="form-control" style="width:250px;margin-left:-15px;">
                                                        <option value="0">请选择商品分类</option>
                                                        <foreach name="second_cat_list" item="v" key="k">
                                                            <option value="{$v['id']}" <if condition="$v['id'] eq $goodsInfo['second_cat_id']">selected="selected"</if> > {$v['name']}
                                                            </option>
                                                        </foreach>
                                                    </select>
                                                </div>
                                                <span id="err_cat_id" style="color:#F00; display:none;"></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class = "text-right">本店售价:</td>
                                            <td>
                                                <input type="text" value="{$goodsInfo.shop_price}" name="shop_price" class="form-control" style="width:150px;" onkeyup="this.value = this.value.replace(/[^\d.]/g, '')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" />
                                                <span id="err_shop_price" style="color:#F00; display:none;"></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class = "text-right">市场价:</td>
                                            <td>
                                                <input type="text" value="{$goodsInfo.mk_price}" name="mk_price" class="form-control" style="width:150px;" onkeyup="this.value = this.value.replace(/[^\d.]/g, '')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" />
                                                <span id="err_market_price" style="color:#F00; display:none;"></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class = "text-right">上传商品图片:</td>
                                            <td>
                                                <input type="file" name="thumb" />
                                                <if condition="$goodsInfo.thumb neq ''">
                                                    <img src="{$goodsInfo.thumb}" width="100" height="100">
                                                </if>
                                            </td>
                                    </tr>
                                    <tr>
                                        <td class = "text-right">赠送积分:</td>
                                        <td>
                                            <input type="text" class="form-control" style="width:150px;" value="{$goodsInfo.give_integral}" name="give_integral" onkeyup="this.value = this.value.replace(/[^\d.]/g, '')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" />
                                            <span id="err_give_integral" style="color:#F00; display:none;"></span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class = "text-right">商品关键词:</td>
                                        <td>
                                            <input type="text" class="form-control" style="width:550px;" value="{$goodsInfo.keywords}" name="keywords" />用空格分隔
                                            <span id="err_keywords" style="color:#F00; display:none;"></span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class = "text-right">是否热卖推荐:</td>
                                        <td>
                                            <label><input type="radio" name="is_hot" value="1" <if condition="$goodsInfo['is_hot'] eq 1">checked</if>> 是 </label>
                                            <label style="margin-left:30px;"><input type="radio" name="is_hot" value="0" <if condition="$goodsInfo['is_hot'] eq 0">checked</if>> 否</label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class = "text-right">是否新品速递:</td>
                                        <td>
                                            <label><input type="radio" name="is_new" value="1" <if condition="$goodsInfo['is_new'] eq 1">checked</if>> 是 </label>
                                            <label style="margin-left:30px;"><input type="radio" name="is_new" value="0" <if condition="$goodsInfo['is_new'] eq 0">checked</if>> 否</label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class = "text-right">是否显示:</td>
                                        <td>
                                            <label><input type="radio" name="status" value="1" <if condition="$goodsInfo['status'] eq 1">checked</if>> 显示 </label>
                                            <label style="margin-left:30px;"><input type="radio" name="status" value="0" <if condition="$goodsInfo['status'] eq 0">checked</if>> 不显示</label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class = "text-right">商品详情描述:</td>
                                        <td width="85%">
                                            <textarea class="span12 ckeditor" id="goods_content" name="goods_content" title="">{$goodsInfo.goods_content}</textarea>
                                            <span id="err_goods_content" style="color:#F00; display:none;"></span>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                            <div class="tab-pane" id="tab_goods_img">
                                <table class="table table-bordered">
                                    <tbody>
                                        <tr>
                                            <td>
                                    <foreach name="goodsImg" item="vo" key="k">
                                        <div style="width:100px; text-align:center; margin: 5px; display:inline-block;" class="goods_xc">
                                            <input type="hidden" value="{$vo['images']}" name="goods_img[]">
                                            <a onclick="" href="{$vo['images']}" target="_blank"><img width="100" height="100" src="{$vo['images']}"></a>
                                            <br>
                                            <a href="javascript:;" onclick="ClearPicArr2(this, '{$vo['images']}')">删除</a>
                                        </div>
                                    </foreach>
                                    <div class="goods_xc" style="width:100px; text-align:center; margin: 5px; display:inline-block;">
                                        <input type="hidden" name="goods_img[]" value="" />
                                        <a href="javascript:;" onclick="GetUploadify(10, '', 'goods', 'call_back2');"><img src="/Public/images/add-button.jpg" width="100" height="100" /></a>
                                        <br/>
                                        <a href="javascript:;">&nbsp;&nbsp;</a>
                                    </div>
                                    </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                            <div class="tab-pane" id="tab_goods_spec">
                                <table style="margin-top: 20px;" id="spec_list">
                                    <tr>
                                        <td width="80">规格名称:</td>
                                        <td width="150">
                                            <input type="hidden" name="spec_id[]" value="{$spec_list[0]['id']}">
                                            <input name="spec_name[]" type="text" class="form-control" value="{$spec_list[0]['spec_name']}">
                                        </td>
                                        <td width="120" style="padding-left:40px;">规格价格:</td>
                                        <td width="150">
                                            <input name="spec_price[]" value="{$spec_list[0]['spec_price']}" type="text" class="form-control" onkeyup="this.value = this.value.replace(/[^\d.]/g, '')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')">
                                        </td>
                                        <td width="120" style="padding-left:40px;">规格原价:</td>
                                        <td width="150">
                                            <input name="spec_mk_price[]" type="text" value="{$spec_list[0]['spec_mk_price']}" class="form-control" onkeyup="this.value = this.value.replace(/[^\d.]/g, '')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')">
                                        </td>
                                        <td style="padding-left:40px;"><span class="btn btn-default" onclick="add_spec();">添加</span></td>
                                    </tr>
                                    <volist name="spec_list" id="val" offset="1">
                                        <tr>
                                            <td width="80" style="padding-top:30px;">规格名称:</td>
                                            <td width="150" style="padding-top:30px;">
                                                <input type="hidden" name="spec_id[]" value="{$val.id}">
                                                <input name="spec_name[]" type="text" class="form-control" value="{$val.spec_name}">
                                            </td>
                                            <td width="120" style="padding-left:40px;padding-top:30px;">规格价格:</td>
                                            <td width="150" style="padding-top:30px;">
                                                <input name="spec_price[]" type="text" value="{$val.spec_price}" class="form-control" onkeyup="this.value = this.value.replace(/[^\d.]/g, '')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')">
                                            </td>
                                            <td width="120" style="padding-left:40px;padding-top:30px;">规格原价:</td>
                                            <td width="150" style="padding-top:30px;">
                                                <input name="spec_mk_price[]" type="text" value="{$val.spec_mk_price}" class="form-control" onkeyup="this.value = this.value.replace(/[^\d.]/g, '')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')">
                                            </td>
                                        </tr>
                                    </volist>
                                </table>
                            </div>
                        </div>
                        <div class="pull-right">
                            <input type="hidden" name="act" value="{$act}">
                            <input type="hidden" name="id" value="{$goodsInfo.id}">
                            <input type="submit" class="btn btn-primary" value="保存">
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </section>
</div>
</body>
<script>
    function add_spec(){
        var html='<tr>';
        html+='<td width="80" style="padding-top:30px;">规格名称:</td>';
        html+='<td width="150" style="padding-top:30px;">';
        html+='        <input name="spec_name[]" type="text" class="form-control"><input type="hidden" name="spec_id[]" value="0">';
        html+='</td>';
        html+='<td width="120" style="padding-left:40px;padding-top:30px;">规格价格:</td>';
        html+='<td width="150" style="padding-top:30px;">';
        html+='    <input name="spec_price[]" type="text" class="form-control">';
        html+='</td>';
        html+='<td width="120" style="padding-left:40px;padding-top:30px;">规格原价:</td>';
        html+='<td width="150" style="padding-top:30px;">';
        html+='    <input name="spec_mk_price[]" type="text" class="form-control">';
        html+='</td>';
        html+='</tr>';
        $('#spec_list').append(html);
    }
    // 上传商品相册回调函数
    function call_back2(paths) {
        var last_div = $(".goods_xc:last").prop("outerHTML");
        for (i = 0; i < paths.length; i++) {
            $(".goods_xc:eq(0)").before(last_div); // 插入一个 新图片
            $(".goods_xc:eq(0)").find('a:eq(0)').attr('href', paths[i]).attr('onclick', '').attr('target', "_blank"); // 修改他的链接地址
            $(".goods_xc:eq(0)").find('img').attr('src', paths[i]); // 修改他的图片路径
            $(".goods_xc:eq(0)").find('a:eq(1)').attr('onclick', "ClearPicArr2(this,'" + paths[i] + "')").text('删除');
            $(".goods_xc:eq(0)").find('input').val(paths[i]); // 设置隐藏域 要提交的值
        }
    }
    function ClearPicArr2(obj, path) {
        $.ajax({
            type: 'GET',
            url: "{:U('Admin/Uploadify/delupload')}",
            data: {
                action: "del",
                filename: path
            },
            success: function () {
                $(obj).parent().remove(); // 删除完服务器的, 再删除 html上的图片
            }
        });
        // 删除数据库记录
        $.ajax({
            type: 'GET',
            url: "{:U('Admin/Goods/delGoodsImg')}",
            data: {
                filename: path
            },
            success: function () {
                //
            }
        });
    }
</script>
</html>
